#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,a[500010],dp[500010],l,r,x[500010],d1[500010],hed1=1,tal1,d2[500010],hed2=1,tal2,j,ans;
signed main(){
	freopen("gonna.in","r",stdin);
	freopen("gonna.out","w",stdout);
	scanf("%lld",&n);
	x[0]=1e18;
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		dp[i]=1e18,x[i]=1e18;
	}
	scanf("%lld",&m);
	while(m--){
		scanf("%lld%lld",&l,&r);
		x[l]=min(x[l],r);
	}
	d1[++tal1]=0,d2[++tal2]=0;
	for(int i=1;i<=n;i++){
		while(x[i]<x[d1[tal1]]&&tal1>=hed1) tal1--;
		d1[++tal1]=i;
		while(x[d1[hed1]]<i){
			j++;
			while(d1[hed1]<=j&&hed1<=tal1) hed1++;
		}
		while(d2[hed2]<j&&hed2<=tal2) hed2++;
		dp[i]=dp[d2[hed2]]+a[i];
		while(dp[i]<dp[d2[tal2]]&&tal2>=hed2) tal2--;
		d2[++tal2]=i;
	}
	ans=dp[n];
	for(int i=n;;i--)
		if(x[i]==1e18) ans=min(ans,dp[i-1]);
		else break;
	printf("%lld",ans);
	return 0;
}
